package com.drinks.yiniang.common.recycler.decoration;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.drinks.yiniang.App;
import com.hansen.library.utils.ScreenSizeUtils;

import static com.drinks.yiniang.entity.user.order.MyOrderJson.ITEM_TYPE_ORDER_TOP;

/**
 * @author han
 * @date 2019/9/7
 */
public class MyOrderItemDecoration extends RecyclerView.ItemDecoration {
    private int space;

    private MyOrderItemDecoration(int space) {

        this.space = space;

    }

    public static MyOrderItemDecoration getItemDecoration(int space) {
        space = ScreenSizeUtils.dp2px(App.getInstance().getApplicationContext(), space);

        return new MyOrderItemDecoration(space);
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        // Add top margin only for the first item to avoid double space between items

        int pos = parent.getChildLayoutPosition(view);

        if(parent.getAdapter() != null && parent.getAdapter().getItemViewType(pos) == ITEM_TYPE_ORDER_TOP) {
            outRect.top = space;
        } else {
            outRect.top = 0;
        }
    }
}
